package cn.stylefeng.guns.modular.make.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.make.entity.MakeRailwayPlatform;
import cn.stylefeng.guns.modular.make.model.params.MakeRailwayPlatformParam;
import cn.stylefeng.guns.modular.make.model.result.MakeRailwayPlatformResult;
import cn.stylefeng.guns.modular.make.service.MakeRailwayPlatformService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 月台管理控制器
 */
@Controller
@RequestMapping("/makeRailwayPlatform")
public class MakeRailwayPlatformController extends BaseController {

    private String PREFIX = "/make/makeRailwayPlatform";

    @Autowired
    private MakeRailwayPlatformService makeRailwayPlatformService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/makeRailwayPlatform.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/makeRailwayPlatform_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/makeRailwayPlatform_edit.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(MakeRailwayPlatformParam makeRailwayPlatformParam) {
    	User user = userService.getcurrentUser();
    	
    	MakeRailwayPlatformParam makeRailwayPlatformParam2 = new MakeRailwayPlatformParam();
    	makeRailwayPlatformParam2.setDeptId(user.getDeptId());
    	makeRailwayPlatformParam2.setRailwayPlatformName(makeRailwayPlatformParam.getRailwayPlatformName());
    	MakeRailwayPlatformResult makeRailwayPlatformResult = makeRailwayPlatformService.findBySpec(makeRailwayPlatformParam2,user.getOperateId());
    	if(makeRailwayPlatformResult != null) {
    		return ResponseData.error("月台名称已存在！请勿重复添加");
    	}
    	
    	makeRailwayPlatformParam.setDeptId(user.getDeptId());
    	makeRailwayPlatformParam.setDeliverId(user.getDeliverId());
    	makeRailwayPlatformParam.setCreateUserName(user.getName());
        this.makeRailwayPlatformService.add(makeRailwayPlatformParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(MakeRailwayPlatformParam makeRailwayPlatformParam) {
    	User user = userService.getcurrentUser();
    	
    	MakeRailwayPlatformParam makeRailwayPlatformParam2 = new MakeRailwayPlatformParam();
    	makeRailwayPlatformParam2.setDeptId(user.getDeptId());
    	makeRailwayPlatformParam2.setRailwayPlatformName(makeRailwayPlatformParam.getRailwayPlatformName());
    	MakeRailwayPlatformResult makeRailwayPlatformResult = makeRailwayPlatformService.findBySpec(makeRailwayPlatformParam2,user.getOperateId());
    	if(makeRailwayPlatformResult != null) {
    		return ResponseData.error("月台名称已存在！请勿重复添加");
    	}
    	
        this.makeRailwayPlatformService.update(makeRailwayPlatformParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(MakeRailwayPlatformParam makeRailwayPlatformParam) {
        this.makeRailwayPlatformService.delete(makeRailwayPlatformParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(MakeRailwayPlatformParam makeRailwayPlatformParam) {
        MakeRailwayPlatform detail = this.makeRailwayPlatformService.getById(makeRailwayPlatformParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(MakeRailwayPlatformParam makeRailwayPlatformParam,String condition ) {
    	User user = userService.getcurrentUser();
    	makeRailwayPlatformParam.setDeptId(user.getDeptId());
        return this.makeRailwayPlatformService.findPageBySpec(makeRailwayPlatformParam,condition,user.getOperateId());
    }

}


